/**
 * 
 */
package connectors;

import menus.Chat;
import menus.MapSelection;
import controller.Controller;

/**
 * @author Lucas 'Mezmor' Pfister
 * 
 */
public class Delegator {
	public Controller controller;
	private final Chat chat;
	private final MapSelection mapSelector;

	public Delegator(Controller cont, Chat ch, MapSelection mapS) {
		this.controller = cont;
		this.chat = ch;
		this.mapSelector = mapS;

		Thread receiveThread = new Thread(new Runnable() {
			@Override
			public void run() {
				while (!Thread.interrupted()) {
					String recvString = controller.conn.receive();
					System.out.println(recvString + " received"); // print statement
					
					if(recvString.equals(""))
						continue;
					if (recvString.startsWith("CHAT:")) {
						// Delegate to chat
						String fixedRecvString = recvString.substring(5);
						chat.updateText(fixedRecvString);
					} else if (recvString.startsWith("maps\\")) {
						// Delegate to map selection
						mapSelector.repaintMap(recvString);
					} else if (recvString.startsWith("MAP:")){
						
					}
				}
			}
		});
		receiveThread.start();
	}
}